﻿@model IEnumerable<TestSys.Models.courses>
@{
    ViewBag.Title = "CreateTest";
    Layout = "~/Views/Admin/_AdminLayout.cshtml";
    string selectedCourse = String.Empty;
    if (ViewBag.selCrs != null)
    {
        selectedCourse = ViewBag.selCrs;
    }
    TestSys.Models.DataManager dataManager = new TestSys.Models.DataManager();
    TestSys.Models.admininfo currAdm = (from item in dataManager.entity.admininfo where item.generalinfo.Login == User.Identity.Name select item).FirstOrDefault();
    var list = currAdm.courses.ToList();
}
<script language="javascript">
    function add_input() {
        // Создаем новый div-элемент
        var new_input = document.createElement('div');
        // Тут мы уже можем воспользоваться innerHTML потому, что изменения не коснуться всего остального докуметна
        new_input.innerHTML = 'Test №' + document.getElementById('inputi').getElementsByTagName('div').length + '<br><input type="file" accept="xml" name="fileUpload[' +
        document.getElementById('inputi').getElementsByTagName('div').length + ']"/>';
        // Добавляем только что созданный div на страницу
        document.getElementById('inputi').appendChild(new_input);
    }

</script>

<form id="myFrom" action="/Admin/CreateTest" method="post" enctype="multipart/form-data">
    @Html.ValidationSummary(true)
    <h4>
        Select a course:</h4>
    @if (selectedCourse != String.Empty)
    { @Html.DropDownList("course", new SelectList(list, "CourseID", "CourseName", list.Where(x => x.CourseName == selectedCourse).FirstOrDefault().CourseName)) }
    else
    { @Html.DropDownList("course", new SelectList(list, "CourseID", "CourseName")) }
    <h4>
        Select xml files with tests</h4>
    <input type="button" onclick="add_input()" value="Add one more file" />
    <div id="inputi">
    </div>
    <input type="submit" value="Upload" />
</form>
